//
//  PublishQgViewController.m
//  CarTown
//
//  Created by xionghao on 15/8/9.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "PublishQgViewController.h"
#import "Radiogroup.h"
#import "PublishTopTableViewCell.h"
#import "Pubmode.h"
#import "RadioTableViewCell.h"
#import "EidtTableViewCell.h"
#import "ColorPickViewController.h"
#import "CarsrouceTypePickerController.h"
#import "FindCarTableViewController.h"
#import "CarPickModel.h"
#import "CarDetail.h"
#import "CityPickerView.h"
#import "JianjieViewController.h"
#import "CarDetailTableViewCell.h"
#import "Puser.h"
#import "CarSourceType.h"
#import "PostSUSViewController.h"
#import "FindCarMode.h"

@interface PublishQgViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,CityPickerDelegate,ColorPikerDelegate,PostSUSViewControllerDelegate,EidtTableViewCellDelegate>{
    int keyboardHeight;
    BOOL keyboardIsShowing;
}
@property (nonatomic,weak) Radiogroup *group;
@property (nonatomic,weak)
UIButton *bottombtn;

@property (nonatomic,strong) NSArray *dataarray;
@property (strong, nonatomic) IBOutlet UITableView *tableview;

//@property (nonatomic, retain) UITextField *currentTextField;
@property (nonatomic,strong) Pubmode *leixing;
@property (nonatomic,strong) Pubmode *waiguan;
@property (nonatomic,strong) Pubmode *neishi;
@property (nonatomic,strong) Pubmode *shangpai;
@property (nonatomic,strong) CarPickModel *chexing;
@property (nonatomic,strong) Pubmode *qiwangmode;
@property (nonatomic,strong) Pubmode *kuling;
@property (nonatomic,strong) Pubmode *paifang;
@property (nonatomic,strong) Pubmode *jiaohuo;
@property (nonatomic,strong) Pubmode *riqi;
@property (nonatomic,strong) Pubmode *dealtime;
@property (nonatomic,strong) Pubmode *beizhu;
@property (nonatomic,strong) Puser *user;

@end

@implementation PublishQgViewController
-(Puser *)user{
    if (_user==nil) {
        _user=[Puser getUser];
    }
    return _user;
}

-(void)continueClick{
    self.findmode=nil;
    self.qiwangmode=nil;
    [self setupdata];
    
    self.tableview.scrollsToTop=YES;
    [self.tableview reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupTablview];
    [self setupdata];
    [self setupbutton];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getcarname:) name:NoticePostGetCar object:nil];
    // Do any additional setup after loading the view.
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)setupbutton{
   UIView *bottom= [[UIView alloc]initWithFrame:CGRectMake(0, 0, XHScreenwidth, 84)];
    UIButton *buttombtn=[[UIButton alloc]initWithFrame:CGRectMake(16, 24, XHScreenwidth-32, 36)];
    _bottombtn=buttombtn;
    [_bottombtn addTarget:self action:@selector(post) forControlEvents:UIControlEventTouchUpInside];
    [_bottombtn setBackgroundImage:[UIImage imageWithStretchableName:@"bottom_bg"] forState:UIControlStateNormal];
     [_bottombtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_bottombtn setTitle: @"立即发布"forState:UIControlStateNormal];
    [bottom addSubview:buttombtn];
    self.tableview.tableFooterView=bottom;
    
}
-(void)post{
    NSLog(@"---post");
    
    if ([self checkform]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"正在发布..";
       
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        
        NSMutableDictionary *params=[NSMutableDictionary dictionary];
        NSString *action;
        if (self.findmode) {
            action=@"buy_refresh";
            params[@"buy_id"]=self.findmode.ID;
            params[@"car_source_type"]=self.leixing.detail;
            params[@"mid"]=self.chexing.cardetail.ID;
            params[@"brand_name"]=self.chexing.brand.brand_name;
            params[@"car_inside_color"]=self.neishi.detail;
            params[@"car_outside_color"]=self.waiguan.detail;
            params[@"card_address"]=self.shangpai.detail;
        }else{
            action=@"add_buy";
            params[@"type_word"]=self.leixing.detail;
            params[@"b_name"]=self.chexing.brand.brand_name;
            params[@"car_type"]=self.chexing.cardetail.ID;
            params[@"out_c"]=self.waiguan.detail;
            params[@"in_c"]=self.neishi.detail;
            params[@"go_b"]=self.shangpai.detail;

        }
        params[@"action"]=action;
       
        NSInteger power=[self.user.power integerValue];
        if (power==1) {
            params[@"user_id"]=self.user.user_id;
            if (self.findmode) {
            params[@"type"]=@"person";
            }else{
            
            params[@"sole_type"]=self.user.user_msn;
            params[@"sole_name"]=self.user.user_truename;
            }
        }else if (power==5){
            params[@"com_id"]=self.user.com_id;
            params[@"sole_type"]=self.user.shop_categories;
            params[@"sole_name"]=self.user.com_name;
        }else if (power==8){
            params[@"com_id"]=self.user.com_id;
            params[@"parent_id"]=self.user.parent_id;
            params[@"sole_type"]=self.user.shop_categories;
            params[@"sole_name"]=self.user.com_name;
        }
        
        CarSourceType *type=[CarSourceType getcarsoucebyText:self.leixing.detail];
        params[@"type_id"]=type.csid;
        params[@"cat_name"]=self.chexing.carporgchild.cat_name;
        params[@"cat_id"]=self.chexing.carporgchild.cat_id;
        params[@"car_name"]=self.chexing.cardetail.name;
       
        
        if (![self.qiwangmode.detail isEqualToString:@""]&&self.qiwangmode.detail) {
            if (self.findmode) {
                params[@"sysprice"]=self.qiwangmode.detail;
            }else{
            params[@"deal_p"]=self.qiwangmode.detail;
            }
        }
        if (self.kuling.radioindex!=-1) {
            switch (self.kuling.radioindex) {
                case 0:
                    if (self.findmode) {
                         params[@"store_age"]=@"3";
                    }else{
                        params[@"sta_ask"]=@"3";
                    }
                   
                    break;
                case 1:
                    if (self.findmode) {
                        params[@"store_age"]=@"6";
                    }else{
                    params[@"sta_ask"]=@"6";
                    }
                    break;
                case 2:
                    if (self.findmode) {
                        params[@"store_age"]=@"12";
                    }else{
                        params[@"sta_ask"]=@"12";
                    }

                    break;
                case 3:
                    if (self.findmode) {
                        params[@"store_age"]=@"0";
                    }else{
                        params[@"sta_ask"]=@"0";
                    }

                    break;
                default:
                    break;
            }
        }
        if (self.paifang.radioindex!=-1) {
            switch (self.paifang.radioindex) {
                case 0:
                    if (self.findmode) {
                        params[@"standard"]=@"4";
                    }else{
                        params[@"stand"]=@"4";
                    }
                    
                    break;
                case 1:
                    if (self.findmode) {
                        params[@"standard"]=@"5";
                    }else{
                        params[@"stand"]=@"5";
                    }

                    break;
                case 2:
                    if (self.findmode) {
                        params[@"standard"]=@"0";
                    }else{
                        params[@"stand"]=@"0";
                    }
                    break;
                default:
                    break;
            }
        }
        if (self.riqi.radioindex!=-1) {
            switch (self.riqi.radioindex) {
                case 0:
                    if (self.findmode) {
                        params[@"deal_time"]=@"3";
                    }else{
                        params[@"de_time"]=@"3";
                    }
                    break;
                case 1:
                    if (self.findmode) {
                        params[@"deal_time"]=@"7";
                    }else{
                        params[@"de_time"]=@"7";
                    }
                    break;
                case 2:
                    if (self.findmode) {
                        params[@"deal_time"]=@"15";
                    }else{
                        params[@"de_time"]=@"15";
                    }
                    break;
                case 3:
                    if (self.findmode) {
                        params[@"deal_time"]=@"99";
                    }else{
                        params[@"de_time"]=@"99";
                    }
                    break;
                default:
                    break;
            }
        }

        if (self.dealtime.radioindex!=-1) {
            switch (self.dealtime.radioindex) {
                case 0:
                    if (self.findmode) {
                        params[@"valid_time"]=@"3";
                    }else{
                        params[@"v_time"]=@"3";
                    }

                   
                    break;
                case 1:
                    if (self.findmode) {
                        params[@"valid_time"]=@"5";
                    }else{
                        params[@"v_time"]=@"5";
                    }
                    break;
                case 2:
                    if (self.findmode) {
                        params[@"valid_time"]=@"7";
                    }else{
                        params[@"v_time"]=@"7";
                    }
                    
                    break;
                case 3:
                    if (self.findmode) {
                        params[@"valid_time"]=@"15";
                    }else{
                        params[@"v_time"]=@"15";
                    }
                    break;
                default:
                    break;
            }
        }
        if (self.beizhu.detail&&![self.beizhu.detail isEqualToString:@"请输入"]) {
            
            if (self.findmode) {
                params[@"car_configure"]=self.beizhu.detail;
            }else{
            params[@"conf"]=self.beizhu.detail;
            }
        }
        if (self.jiaohuo.detail&&![self.jiaohuo.detail isEqualToString:@"请选择"]) {
            
            if (self.findmode) {
                params[@"deal_address"]=self.jiaohuo.detail;
            }else{
            params[@"deal_ad"]=self.jiaohuo.detail;
            }
        }
        
        NSString *url;
        if (self.findmode) {
            url=myfindcarurl;
        }else{
            url=addfindcar;
        }
        
        [PostUitls Post:url parameters:params success:^(id response) {
           
            NSDictionary *dict=response;
            
            NSNumber *number=dict[@"state"];
            if ([number integerValue]==400) {
                 NSNumber *data=dict[@"data"];
                PostSUSViewController *vc=[PostSUSViewController viewcontroller];
                vc.delegate=self;
                if (self.findmode) {
                    vc.type=POSTFINDCARTYPEFROMEIDT;
                }else{
                vc.type=POSTFINDCARTYPE;
                }
                vc.ID=[data stringValue];
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                hud.mode=MBProgressHUDModeText;
                hud.labelText=dict[@"msg"];
            }
            
            [hud hide:YES afterDelay:0.5];
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            hud.mode=MBProgressHUDModeText;
            hud.labelText=@"网络错误";
            [hud hide:YES afterDelay:0.5];

            
        }];
        
    }
}
-(BOOL)checkform{
    if ([self.leixing.detail isEqualToString:@"请选择"]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请选择车源类型";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    if ([self.chexing.detail isEqualToString:@"请选择"]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请选择车型";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    if ([self.waiguan.detail isEqualToString:@"请选择"]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请选择外观颜色";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    if ([self.neishi.detail isEqualToString:@"请选择"]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请选择内饰颜色";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    if ([self.shangpai.detail isEqualToString:@"请选择"]) {
        MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.labelText=@"请选择上牌地点";
        hud.mode = MBProgressHUDModeText;
        hud.margin = 10.f;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        return NO;
    }
    return YES;
    
}

+(instancetype)publish{
    PublishQgViewController *plqvc=[[PublishQgViewController alloc]initWithNibName:@"PublishQgViewController" bundle:nil];
    plqvc.hidesBottomBarWhenPushed=YES;
    plqvc.navigationItem.title=@"发求购";
    return plqvc;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section!=0) {
        return 24;
    }else{
        return 0;
    }
}
#pragma -mark 车型选择回调
-(void)getcarname:(NSNotification *)notice{
    [self clearother];
    CarDetail *detail=notice.userInfo[@"cardetail"];
    CarbrandModel *brand=notice.userInfo[@"brand"];
    CarprogChildmode *carprogchild=notice.userInfo[@"cartory"];
    self.chexing.detail=detail.name;
    self.chexing.cardetail=detail;
    self.chexing.carporgchild=carprogchild;
    self.chexing.brand=brand;

    NSIndexPath *indexpath=[NSIndexPath indexPathForRow:1 inSection:0];
    NSIndexPath *indexpath1=[NSIndexPath indexPathForRow:2 inSection:0];
    NSIndexPath *indexpath2=[NSIndexPath indexPathForRow:3 inSection:0];
    [self.tableview reloadRowsAtIndexPaths:@[indexpath,indexpath1,indexpath2] withRowAnimation:UITableViewRowAnimationAutomatic];
    
}



#pragma -mark 上牌地点选择回调
-(void)citypicker:(NSString *)city withPicker:(CityPickerView *)picker{
    
    switch (picker.tag) {
        case 0:
        {
            self.shangpai.detail=city;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:4 inSection:0];
            [self.tableview reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
        }
            break;
        case 1:
        {
            self.jiaohuo.detail=city;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:3 inSection:1];
            [self.tableview reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
        }
            break;
        default:
            break;
    }
   
    
}

#pragma -mark 颜色选择回调
-(void)ColorPikcerClickContoller:(ColorPickViewController *)picker withIndex:(NSInteger)index ColorStr:(NSString *)colorstr{
    NSIndexPath *indexpath;
    if(picker.view.tag==0){
        self.waiguan.detail=colorstr;
        self.waiguan.index=index;
        indexpath=[NSIndexPath indexPathForRow:2 inSection:0];
        
    }else{
        self.neishi.detail=colorstr;
        self.neishi.index=index;
        indexpath=[NSIndexPath indexPathForRow:3 inSection:0];
    }
    [self.tableview reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-(void)clearother{
    self.chexing.cardetail=nil;
    self.chexing.brand=nil;
    self.chexing.carporgchild=nil;
    self.chexing.detail=@"请选择";
    
    self.neishi.detail=@"请选择";
    self.waiguan.detail=@"请选择";
    
}
#pragma -mark 设置数据模型
-(void)setupdata{
    
   
    
    Pubmode *leixing=[[Pubmode alloc]init];
    leixing.name=@"车源类型";
    leixing.index=-1;
    
    if (self.findmode) {
        leixing.detail=self.findmode.car_source_type;
        CarSourceType *type= [CarSourceType getcarsoucebyText:leixing.detail];
        NSArray *array= [CarSourceType getCarSourceType];
        leixing.index=[array indexOfObject:type];
        leixing.csid=type.csid;
        
    }else{
        leixing.detail=@"请选择";
    }

    leixing.block=^{
            CarsrouceTypePickerController *picker=[CarsrouceTypePickerController picker];
            picker.currtpostion=self.leixing.index;
           
            picker.block=^(NSString *str,NSString *cs_id,NSInteger currtpostion){
                
                [self clearother];
                self.leixing.detail=str;
                self.leixing.index=currtpostion;
                self.leixing.csid=cs_id;
                
                NSIndexSet *set=[NSIndexSet indexSetWithIndex:0];
                
                [self.tableview reloadSections:set withRowAnimation:UITableViewRowAnimationAutomatic];
            };
            
            [self.navigationController pushViewController:picker animated:YES];
        };
 
    leixing.isMust=YES;
    self.leixing=leixing;
    CarPickModel *chexing=[[CarPickModel alloc]init];
    chexing.name=@"车型";
    
    if (self.findmode) {
        CarDetail *cardetail=[[CarDetail alloc]init];
        cardetail.name=self.findmode.car_name;
        cardetail.ID=self.findmode.mid;
        CarbrandModel *brand=[[CarbrandModel alloc]init];
        brand.brand_name=self.findmode.brand_name;
         chexing.cardetail=cardetail;
        chexing.brand=brand;
        CarprogChildmode *child=[[CarprogChildmode alloc]init];
        child.cat_name=self.findmode.cat_name;
        child.cat_id=self.findmode.cat_id;
        chexing.carporgchild=child;

    }
    chexing.detail=self.findmode?self.findmode.car_name:@"请选择";
    chexing.isMust=YES;
    chexing.block=^{
        if ([self.leixing.detail isEqualToString:@"请选择"]) {
            MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
            hud.labelText=@"请先选择车源类型";
            hud.mode = MBProgressHUDModeText;
            hud.margin = 10.f;
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:1];
        }else{
            FindCarTableViewController *fincar=[FindCarTableViewController findcar];
            fincar.type=self.leixing.csid;
            [self.navigationController pushViewController:fincar animated:YES];
        }
    };
    self.chexing=chexing;
    
    Pubmode *waiguan=[[Pubmode alloc]init];
    waiguan.name=@"外观颜色";
    waiguan.isMust=YES;
    waiguan.detail=self.findmode?self.findmode.car_outside_color:@"请选择";
    waiguan.block=^{
        
        if ([self.chexing.detail isEqualToString:@"请选择"]) {
            MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
            hud.labelText=@"请先选择车型";
            hud.mode = MBProgressHUDModeText;
            hud.margin = 10.f;
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:1];
        }else{
            ColorPickViewController *color=[ColorPickViewController colorpicker];
            color.delegate=self;
            
            color.ID=self.chexing.cardetail.ID;
            color.index=self.waiguan.index;
            color.colorstr=self.waiguan.detail;
            color.isOut=YES;
            color.view.tag=0;
            [self.navigationController pushViewController:color animated:YES];}
    };
    self.waiguan=waiguan;
    Pubmode *leishi=[[Pubmode alloc]init];
    leishi.name=@"内饰颜色";
    leishi.isMust=YES;
    leishi.detail=self.findmode?self.findmode.car_inside_color:@"请选择";
    self.neishi=leishi;
    leishi.block=^{
        
        if ([self.chexing.detail isEqualToString:@"请选择"]) {
            MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
            hud.labelText=@"请先选择车型";
            hud.mode = MBProgressHUDModeText;
            hud.margin = 10.f;
            
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:1];
        }else{
            ColorPickViewController *color=[ColorPickViewController colorpicker];
            color.delegate=self;
            
            color.ID=self.chexing.cardetail.ID;
            color.index=self.neishi.index;
            color.colorstr=self.waiguan.detail;
            color.isOut=NO;
            color.view.tag=1;            [self.navigationController pushViewController:color animated:YES];}
        
    };

    Pubmode *shangpai=[[Pubmode alloc]init];
    shangpai.name=@"上牌地点";
    shangpai.isMust=YES;
    shangpai.detail=self.findmode.card_address?self.findmode.card_address:@"请选择";
    shangpai.block=^{
        CityPickerView *pickcer=[[CityPickerView alloc]initWithDelegate:self WithColoum:3];
        pickcer.tag=0;
        [pickcer showinView:self.navigationController.view];
    };
    self.shangpai=shangpai;
    Pubmode *qiwangmode=[[Pubmode alloc]init];
    qiwangmode.name=@"期望成交价";
    qiwangmode.isEidt=YES;
    qiwangmode.isMust=NO;
    qiwangmode.detail=self.findmode.sysprice;
    self.qiwangmode=qiwangmode;
    Pubmode *kuling=[[Pubmode alloc]init];
    kuling.name=@"库龄要求";
    kuling.radioindex=-1;
    if (self.findmode) {
        switch ([self.findmode.store_age integerValue]) {
            case 3:
                kuling.radioindex=0;
                break;
            case 6:
                kuling.radioindex=1;
                break;
            case 12:
                kuling.radioindex=2;
                break;
            case 0:
                kuling.radioindex=3;
                break;
            default:
                kuling.radioindex=-1;
                break;
        }

    }
    kuling.titlearray=@[@"3个月",@"6个月",@"12个月",@"不限"];
    self.kuling=kuling;
    Pubmode *paifang=[[Pubmode alloc]init];
    paifang.name=@"排放标准";
    paifang.radioindex=-1;
    paifang.titlearray=@[@"国四",@"国五",@"不限"];
    if (self.findmode) {
        switch ([self.findmode.standard integerValue]) {
            case 4:
                paifang.radioindex=0;
                break;
            case 5:
                paifang.radioindex=1;
                break;
            case 0:
                paifang.radioindex=2;
                break;
            default:
                paifang.radioindex=-1;
                break;
        }

    }
        self.paifang=paifang;
    Pubmode *jaohuo=[[Pubmode alloc]init];
    jaohuo.name=@"交车地点";
    jaohuo.isMust=NO;
    jaohuo.detail=self.findmode?self.findmode.deal_address:@"请选择";
    jaohuo.block=^{
        CityPickerView *pickcer=[[CityPickerView alloc]initWithDelegate:self WithColoum:3];
        pickcer.tag=1;
        [pickcer showinView:self.navigationController.view];
    };
    self.jiaohuo=jaohuo;
    Pubmode *riqi=[[Pubmode alloc]init];
    riqi.name=@"交车日期";
    riqi.radioindex=-1;
    if (self.findmode) {
        switch ([self.findmode.deal_time integerValue]) {
            case 3:
                riqi.radioindex=0;
                break;
                
            case 7:
                riqi.radioindex=1;
                break;
            case 15:
                riqi.radioindex=2;
                break;
            case 99:
                riqi.radioindex=3;
                break;
            default:
                riqi.radioindex=-1;
                break;
        }

    }
    riqi.titlearray=@[@"3天",@"7天",@"15天",@"期货"];
    self.riqi=riqi;
    Pubmode *youxiao=[[Pubmode alloc]init];
    youxiao.name=@"求购有效期";
    youxiao.radioindex=0;
    youxiao.isNotCancel=YES;
    switch ([self.findmode.valid_time integerValue]) {
        case 3:
            youxiao.radioindex=0;
            break;
        case 5:
            youxiao.radioindex=1;
            break;
        case 7:
            youxiao.radioindex=2;
            break;
        case 15:
            youxiao.radioindex=3;
            break;
        default:
            break;
    }
    youxiao.titlearray=@[@"3天",@"5天",@"7天",@"15天"];
    self.dealtime=youxiao;
    Pubmode *beizhu=[[Pubmode alloc]init];
    beizhu.name=@"备注";
    beizhu.isMust=NO;
    beizhu.detail=self.findmode.car_configure?self.findmode.car_configure:@"请输入";
    self.beizhu=beizhu;
    beizhu.block=^{
        JianjieViewController *jjvc=[JianjieViewController viewcontroller];
        jjvc.navtitle=@"备注";
        jjvc.text=[beizhu.detail isEqualToString:@"请输入"]?@"":beizhu.detail;
        jjvc.block=^(NSString *str){
            self.beizhu.detail=str;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:6 inSection:1];
            [self.tableview reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];
            
        };
        [self.navigationController pushViewController:jjvc animated:YES];
    };

    
    _dataarray=@[@[leixing,chexing,waiguan,leishi,shangpai],@[qiwangmode,kuling,paifang,jaohuo,riqi,youxiao,beizhu]];
}
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
   }
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    }
-(void)setupTablview{
    
    self.tableview.backgroundColor=bgGarycolor;
    UINib *top=[UINib nibWithNibName:NSStringFromClass([PublishTopTableViewCell class]) bundle:nil];
    UINib *radio=[UINib nibWithNibName:NSStringFromClass([RadioTableViewCell class]) bundle:nil];
     UINib *edit=[UINib nibWithNibName:NSStringFromClass([EidtTableViewCell class]) bundle:nil];
    [_tableview registerNib:top  forCellReuseIdentifier:@"top"];
    [_tableview registerNib:edit  forCellReuseIdentifier:@"editcell"];
      [_tableview registerNib:radio  forCellReuseIdentifier:@"radio"];
    if ([self.tableview respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableview setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([self.tableview respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [self.tableview setLayoutMargins:UIEdgeInsetsZero];
        
    }
}


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataarray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *array=self.dataarray[section];
    return array.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    Pubmode *mode=array[indexPath.row];
    if (mode.titlearray) {
        RadioTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"radio"];
        cell.mode=mode;
        return cell;
    }else if (mode.isEidt){
        EidtTableViewCell *cell=[EidtTableViewCell cellWithTable:tableView];
        cell.titlelable.text=mode.name;
        cell.ismust.hidden=!mode.isMust;
        cell.delegate=self;
        return cell;
    } else if ([mode isKindOfClass:[CarPickModel class]]&&[self.leixing.detail isEqualToString:@"中规"]&&!self.findmode){
        CarDetailTableViewCell *cell=[CarDetailTableViewCell cellwithTablview:tableView];
        if (self.chexing.cardetail) {
            cell.carname.text=self.chexing.cardetail.name;
             cell.price.textColor=textnormalGary;
             cell.carname.textColor=textnormalGary;
            cell.price.text=[NSString stringWithFormat:@"%@",self.chexing.cardetail.price];
        }else{
            cell.carname.text=nil;
            cell.price.text=@"请选择";
             cell.price.textColor=placehodlerColor;
             cell.carname.textColor=placehodlerColor;
        }
        
        return cell;
    }
    
    else {
        PublishTopTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"top"];
        cell.titlelable.text=mode.name;
        cell.detail.text=mode.detail;
        if ([mode.detail isEqualToString:@"请选择"]||[mode.detail isEqualToString:@"请输入"]) {
            cell.detail.textColor=placehodlerColor;
        }else{
            cell.detail.textColor=textnormalGary;
        }
        cell.startlable.hidden=!mode.isMust;
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array=self.dataarray[indexPath.section];
    Pubmode *mode=array[indexPath.row];
    if (mode.block) {
        mode.block();
    }

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
